fn main() {
    println!("流程控制");

    // if
    let n = 5;
    let big_n = if n < 10 && n > -10 {
        println!("-10~10");
        n * 2
    } else {
        n
    };
    println!("if else: {}", big_n);

    println!("loop 无限循环, break 跳出");
    let mut count = 0;
    loop {
        count += 1;
        if count == 3 {
            println!("达到3, 跳过");
            continue;
        }
        if count == 5 {
            println!("达到5, 跳出");
            break;
        }
    }

    println!("多重循环中用标签,达到跳出指定循环的目的.");
    #[allow(unreachable_code, unused_labels)] // 允许未使用的代码
    'outer: loop {
        println!("这是外循环");
        'inner: loop {
            println!("这是内循环");
            break 'outer; // 跳出外循环
        }
    }

    println!("while 条件循环");
    let mut n = 1;
    println!("https://en.wikipedia.org/wiki/Fizz_buzz");
    println!("力扣题: https://leetcode.cn/problems/fizz-buzz/");
    while n < 101 {
        if n % 15 == 0 {
            println!("fizzbuzz ");
        } else if n % 3 == 0 {
            print!("fizz ");
        } else if n % 5 == 0 {
            print!("buzz ");
        } else {
            print!("{} ", n);
        }
        n += 1;
    }
    println!("");
    println!("for 区间循环");
    // // 左闭右开
    // for n in 1..101 {
    // // 左闭右闭
    for n in 1..=100 {
        if n % 15 == 0 {
            println!("fizzbuzz ");
        } else if n % 3 == 0 {
            print!("fizz ");
        } else if n % 5 == 0 {
            print!("buzz ");
        } else {
            print!("{} ", n);
        }
    }

    println!("for 迭代器: 引用iter, 可变iter_mut, 借用into_iter, ");
    let names = vec!["张三", "李四", "王五"];
    for name in names.iter() {
        print!("{}, ", name);
    }
    println!("");
    println!("iter 后变量仍可用: {:?}", names);

    let mut names: Vec<String> = ["张三", "李四", "王五"]
        .iter()
        .map(|s| s.to_string())
        .collect();
    for name in names.iter_mut() {
        *name = format!("{}.改", *name);
    }
    println!("iter_mut 后: {:?}", names);

    let names = vec!["张三", "李四", "王五"];
    for name in names.into_iter() {
        print!("{}, ", name);
    }
    // println!("into_iter 后: {:?}", names); // value borrowed here after move
}
